$(document).ready(function(){
	loadOpenTopicInNewWindow();
});

//切换是否新窗打开帖子
function switchTopicOpenMode() {
	var mode = $("#topicOpenMode:checked").length === 1;
	if (mode) {
		$("a.topicurl").attr("target", "_blank");
		$.cookie("dontOpenTopicInNewWindow", 0, {
			expires : 100
		});
	} else {
		$("a.topicurl").removeAttr("target");
		$.cookie("dontOpenTopicInNewWindow", 1, {
			expires : 100
		});
	}
}
//读是否新窗打开帖子的cookie
function loadOpenTopicInNewWindow(){
	if ($.cookie("dontOpenTopicInNewWindow") === "1") {
		$("#topicOpenMode").removeAttr("checked");
		$("a.topicurl").removeAttr("target");
	}
}

//初始化回复编辑器
function initReplyEditor(selector, ctrlEnter){
	var emots={
		msn:{name:'MSN',count:40,width:22,height:22,line:8},
		pidgin:{name:'Pidgin',width:22,height:25,line:8,list:{smile:'微笑',cute:'可爱',wink:'眨眼',laugh:'大笑',victory:'胜利',sad:'伤心',cry:'哭泣',angry:'生气',shout:'大骂',curse:'诅咒',devil:'魔鬼',blush:'害羞',tongue:'吐舌头',envy:'羡慕',cool:'耍酷',kiss:'吻',shocked:'惊讶',sweat:'汗',sick:'生病',bye:'再见',tired:'累',sleepy:'睡了',question:'疑问',rose:'玫瑰',gift:'礼物',coffee:'咖啡',music:'音乐',soccer:'足球',good:'赞同',bad:'反对',love:'心',brokenheart:'伤心'}},
		ipb:{name:'IPB',width:20,height:25,line:8,list:{smile:'微笑',joyful:'开心',laugh:'笑',biglaugh:'大笑',w00t:'欢呼',wub:'欢喜',depres:'沮丧',sad:'悲伤',cry:'哭泣',angry:'生气',devil:'魔鬼',blush:'脸红',kiss:'吻',surprised:'惊讶',wondering:'疑惑',unsure:'不确定',tongue:'吐舌头',cool:'耍酷',blink:'眨眼',whistling:'吹口哨',glare:'轻视',pinch:'捏',sideways:'侧身',sleep:'睡了',sick:'生病',ninja:'忍者',bandit:'强盗',police:'警察',angel:'天使',magician:'魔法师',alien:'外星人',heart:'心动'}}
	};
	
	loadMultiJS(
		[
		 	mlog.variable.base + '/script/xheditor/xheditor.js',
		 	mlog.variable.base + '/script/xheditor/xheditor_plugins/ubb.js'
		],
		function(){
			///*Img,Emot,*/
			$(selector).xheditor({tools:'Fontface,FontSize,FontColor,BackColor,Bold,Italic,Underline,Strikethrough,Link,Unlink,Source',showBlocktag:false,forcePtag:false,emots:emots,emotMark:true,shortcuts:{'ctrl+enter':ctrlEnter}});
		}
	);
}

//显示回复本楼
function showReplyThis(id){
	$('#' + id).toggle('normal');
}

//加载单个JS文件
function loadJS(url,callback){
	var head = document.getElementsByTagName("head")[0];
	var script = document.createElement('script');
	script.onload = script.onreadystatechange = script.onerror = function (){
		if (script && script.readyState && /^(?!(?:loaded|complete)$)/.test(script.readyState)) return;
		script.onload = script.onreadystatechange = script.onerror = null;
		script.src = '';
		script.parentNode.removeChild(script);
		script = null;
		callback();
	}
	script.charset = "UTF-8";
	script.src = url;
	try {
		head.appendChild(script);
	} catch (exp) {}
}

//加载多个JS文件
function loadMultiJS(url,callback){
	if(Object.prototype.toString.call(url)==='[object Array]'){	//是否数组
		this.suc = 0;			//加载计数
		this.len = url.length;	//数组长度
		var a = this;
		for(var i = 0;i < url.length;i++){
			loadJS(url[i],function(){ a.suc++; if(a.suc == a.len) try{callback();}catch(e){} });
		}
	}else if(typeof(url) == 'string'){
		loadJS(url,callback);
	}
}
